package com.hmall.api.item;

import com.hmall.api.item.dto.ItemDTO;
import com.hmall.api.item.dto.OrderDetailDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

/**
 * Item 降级工厂
 *
 * @author Zhy
 * @version 1.0
 * @date 2025-03-17 10:49
 */
@Slf4j
@Component
public class ItemClientFallbackFactory implements FallbackFactory<ItemClient> {

	@Override
	public ItemClient create(Throwable cause) {
		return new ItemClient() {
			@Override
			public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
				log.warn("远程调用ItemClient queryItemByIds方法出现降级，参数：{}", ids);
				return List.of();
			}

			@Override
			public void deductStock(List<OrderDetailDTO> items) {
				log.warn("远程调用ItemClient deductStock方法出现降级，参数：{}", items);
			}
		};
	}

}
